package com.sgb.knowledgeshare.view.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.knowledgeshare.R;
import com.sgb.knowledgeshare.entity.VideoFileBean;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

/**
 * Created by：冯齐 on 2020/11/20 18:23
 * Description： 分享-发布-相册选择
 */
public class VideoPhotoAdapter extends BaseRecycleAdapter<VideoFileBean> {

    public VideoPhotoAdapter(Context context, List<VideoFileBean> datas) {
        super(context, R.layout.item_video_edit, datas);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, @SuppressLint("RecyclerView") int position) {
        super.onBindViewHolder(holder, position);
        RelativeLayout rleditchoice = holder.itemView.findViewById(R.id.rl_edit_choice);//是否选中布局
        //是否选中状态的布局
        rleditchoice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OnSelectVideoClick.getOnSelectVideoClick(position);
            }
        });

    }

    @Override
    public void convert(ItemViewHolder holder, VideoFileBean bean) {
    //    holder.setBinding(BR.viewModel, bean);
        ImageView editimagev = holder.itemView.findViewById(R.id.edit_imagev);//是否选中的图标
        ImageView editlogo = holder.itemView.findViewById(R.id.edit_logo);//封面图
        TextView edittime = holder.itemView.findViewById(R.id.edit_time);//时间
//        根据状态动态设置是否选中状态
        if (bean.isSelect() == true) {
            editimagev.setImageResource(R.mipmap.share_user_video_select);
        } else {
            editimagev.setImageResource(R.mipmap.share_user_video_no);
        }
        //封面加载
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.share_classify_loading)//图片加载出来前，显示的图片
                .fallback( R.mipmap.share_classify_failure) //url为空的时候,显示的图片
                .error(R.mipmap.share_classify_failure);//图片加载失败后，显示的图片
        Glide.with(context).load(bean.getPath()).apply(options).into(editlogo);
        edittime.setText(DateUtils.generateTime(bean.getSize()));

    }
    private  OnSelectVideoClick OnSelectVideoClick;
    public interface OnSelectVideoClick{
        void getOnSelectVideoClick(int pos);
    }

    public void setOnSelectVideoClick(VideoPhotoAdapter.OnSelectVideoClick onSelectVideoClick) {
        OnSelectVideoClick = onSelectVideoClick;
    }
}
